package com.lzwk.app.function;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * @Author: CC
 * @Date: 2022/3/9 10:40
 */
public class DateUtil {
    public static String dateFormat(String ts) {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z", Locale.ENGLISH);
            Date date = formatter.parse(ts);
            return f.format(date);
        } catch (Exception e) {
            return f.format(new Date());
        }
    }

    public static String dateFormatUTC(String ts) {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z", Locale.ENGLISH);
            Date date = formatter.parse(ts);
            return f.format(new Date(date.getTime()- (long)8 * 60 * 60 * 1000));
        } catch (Exception e) {
            return f.format(new Date(new Date().getTime()- (long)8 * 60 * 60 * 1000));
        }
    }

    public static String dateNow() {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        return f.format(new Date());
    }
}
